package com.wink.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wink.admin.entity.SysUser;
import com.wink.admin.mapper.SysUserMapper;
import com.wink.admin.service.SysUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统用户服务impl
 *
 * @author xw
 * @date 2020-11-20 16:47
 */
@Slf4j
@Service
@AllArgsConstructor
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    private final SysUserMapper areaMapper;

    @Override
    public List<SysUser> getList() {
        // return areaMapper.selectList(null);
        return areaMapper.selectList();
    }

    @Override
    public Boolean addUser(SysUser user) {
        // return areaMapper.insert(user) > 0;
        areaMapper.insert(user);
        System.out.println(user.getId());
        return true;
    }

    @Override
    public Boolean deleteUser(Long id) {
        return areaMapper.deleteById(id) > 0;
    }

    @Override
    public Boolean updateUser(Long id, String password) {
        SysUser user = areaMapper.selectById(id);
        user.setPassword(password);
        return areaMapper.updateById(user) > 0;
    }

    @Override
    public SysUser getOne(Long id) {
        return areaMapper.selectById(id);
    }


    /**
     * test02异步
     * 不指定线程池，会默认new Thread销毁，占用资源
     *
     * @param msg msg
     */
    @Async("threadPoolTaskExecutor")
    @Override
    public void test02Async(String msg) {
        log.error("test02Async->thread name：{}，异步线程使用：{}", Thread.currentThread().getName(), msg);
    }

}
